package cn.wipace.useractionlib;

import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import java.util.ArrayList;
import java.util.List;

import cn.wipace.actionlib.inter.UserInter;
import cn.wipace.actionlib.inter.impl.UserImpl;
import cn.wipace.actionlib.model.UserAction;
import cn.wipace.actionlib.model.UserScore;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    Button mBtnTest1;
    Button mBtnTest2;
    Button mBtnTest3;
    Button mBtnTest4;
    Button mBtnTest5;
    Button mBtnTest6;
    UserInter mUserInter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mBtnTest1 = (Button) findViewById(R.id.id_btn_test1);
        mBtnTest2 = (Button) findViewById(R.id.id_btn_test2);
        mBtnTest3 = (Button) findViewById(R.id.id_btn_test3);
        mBtnTest4 = (Button) findViewById(R.id.id_btn_test4);
        mBtnTest5 = (Button) findViewById(R.id.id_btn_test5);
        mBtnTest6 = (Button) findViewById(R.id.id_btn_test6);
        mBtnTest1.setOnClickListener(this);
        mBtnTest2.setOnClickListener(this);
        mBtnTest3.setOnClickListener(this);
        mBtnTest4.setOnClickListener(this);
        mBtnTest5.setOnClickListener(this);
        mBtnTest6.setOnClickListener(this);
        mUserInter = new UserImpl(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.id_btn_test1:
                for (int i = 0; i < 5; i++) {
                    mUserInter.saveUserActionData(0.211111111f, 0.54444f, i, i, i, i);
                }
                break;
            case R.id.id_btn_test2:
                List<UserAction> list = mUserInter.findUserActionData();
                Log.e("kerry", list.size() + "========记录个数" + list.get(0).getT0());
                Log.e("kerry", list.size() + "========记录个数" + list.get(0).getT1());
                Log.e("kerry", list.size() + "========记录个数" + list.get(0).getT2());
                break;
            case R.id.id_btn_test3:
                for (int i = 0; i < 5; i++) {
                    mUserInter.saveUserScoreData(5, i, i, i, i, i, "userlib", (short) 0, System.currentTimeMillis());
                }
                break;
            case R.id.id_btn_test4:
         /*       List<UserScore> lists = mUserInter.findScoreTop10(2L);
                for (UserScore score : lists) {
                    Log.e("kerry", "userscore===" + DataUtil.transForDate1(score.getGameStartTime()));
                }*/
                UserScore s = new UserScore(50, 60, 70, 90);
                mUserInter.openRadarMapActivity(this, getPackageName(), s);


                break;
            case R.id.id_btn_test5:
               /* UserScore score = new UserScore(11l, 85.6f, 85.6f, 85.6f, 85.6f, 85.6f, "com.wipace.cn", System.currentTimeMillis());
                HttpResultListener<Result> listener = new HttpResultListener<Result>() {
                    @Override
                    public void onSuccess(Result result) {
                        if (null != result) {
                            Log.e("kerrys", result.code + "=====");
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("kerrys", e.getMessage());
                    }
                };

                mUserInter.uploadScoreData(score, listener);*/

                Uri uri = mUserInter.saveScoreByProvider(UserInter.STACK_URIS, "100", this);
                Log.e("kerrys", uri.toString());

              /*  for (int i = 0; i < 5; i++) {
                    SaveUtil.saveValueToRailwayFile(SaveUtil.JELLY_SCORE, i + "", false);
                }*/
                break;
            case R.id.id_btn_test6:
//                String str = SaveUtil.getValueToRailwayFile(SaveUtil.JELLY_SCORE);
//                Log.e("kerry", str);
                /*HttpResultListener<Result> listener2 = new HttpResultListener<Result>() {
                    @Override
                    public void onSuccess(Result result) {
                        if (null != result) {
                            Log.e("kerrys", result.code + "=====" + result.getResult().getPn());
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                    }
                };
                mUserInter.getScoreData(16, listener2);*/


                List<UserScore> list1 = new ArrayList<>();
                list1 = mUserInter.getScoreByProvider(UserInter.STACK_URIS, this);
                for (UserScore score : list1) {
                    Log.e("kerrys", score.getGameScore() + "");
                }
                break;
        }
    }
}

